﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace XNA_Game_Framework
{
	static internal class MenuDraw
	{
		static Menu parent;

		static internal int LineHeight
		{
			get 
			{
				SpriteFont font = parent.Font;
                Vector2 lineSize = font.MeasureString("example");
				return (int)lineSize.Y;
			}
		}

		static internal int LineSeparation
		{
			get
			{
				return parent.SelectionBox.Height - LineHeight;
			}
		}

		static internal int HalfLineSeparation
		{
			get
			{
				return LineSeparation / 2;
			}
		}

		static internal Vector2 SelectionBoxPosition(Vector2 position)
		{
			return new Vector2(position.X - HalfLineSeparation, position.Y - HalfLineSeparation);
		}

		static public void Start(Menu menu, SpriteBatch spriteBatch)
		{
			parent = menu;

			Vector2 linePosition = new Vector2(parent.WindowPosition.X + HalfLineSeparation, parent.WindowPosition.Y + HalfLineSeparation);
			for (int i = 0; i < parent.menuItems.Count(); i++)
			{
				string entry = parent.menuItems[i].Text;
				if (parent.CurrentIndex == i)
				{
					spriteBatch.Draw(parent.SelectionBox, SelectionBoxPosition(linePosition), Color.White);
				}
				spriteBatch.DrawString(parent.Font, entry, linePosition, Color.Black);
				linePosition.Y += parent.SelectionBox.Height;
			}
		}
	}
}
